package com.winit.common.base.bean;

import java.io.Serializable;

public class ExecuteResult<T> implements Serializable{

    public static final String CODE_ERROR_COMMON = "1";

    private String code = "0";
    private String msg = "SUCCESS";
    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess(){
        return "0".equalsIgnoreCase(code);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> ExecuteResult<T> successExecuteResult(Class<T> tClass){
        return new ExecuteResult<T>();
    }

    public static <T> ExecuteResult<T> getExecuteResult(String code, String msg, T data){
        ExecuteResult<T> executeResult = new ExecuteResult<>();
        executeResult.setCode(code);
        executeResult.setMsg(msg);
        executeResult.setData(data);
        return executeResult;
    }

    public void setToError(){
        this.code = CODE_ERROR_COMMON;
        this.setMsg("ERROR");
    }
    public String getDesc() {
        return msg;
    }
    public void toError(String desc) {
        this.code = CODE_ERROR_COMMON;
        this.msg = desc;
    }
    public boolean success() {
        return "0".equalsIgnoreCase(this.code);
    }
    public static <T> ExecuteResult<T> getErrorExecuteResult() {
        ExecuteResult<T> executeResult = new ExecuteResult<>();
        executeResult.setCode(CODE_ERROR_COMMON);
        executeResult.setMsg("ERROR");
        executeResult.setData(null);
        return executeResult;
    }
    public static <T> ExecuteResult<T> getErrorExecuteResult(String desc, T data) {
        ExecuteResult<T> executeResult = new ExecuteResult<>();
        executeResult.setCode(CODE_ERROR_COMMON);
        executeResult.setMsg(desc);
        executeResult.setData(data);
        return executeResult;
    }
    public void setDesc(String desc) {
        this.msg = desc;
    }

}
